﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Systems.Model
{
    public class SystemLogCls
    {
        public string LogAccessId;
        public DateTime LogAccessDate;
        public string Action = "";
        public string ActionText = "";
        public string UserId = "";
        public string LoginName = "";
        public string FullName = "";
    }


    public class SystemLogParser
    {
        public static SystemLogCls CreateInstance()
        {
            //tao 1 class trang....
            SystemLogCls oSystemLogCls = new SystemLogCls();
            return oSystemLogCls;
        }

        public static SystemLogCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            SystemLogCls oSystemLogCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oSystemLogCls;
        }


        public static SystemLogCls ParseFromDataRow(DataRow dr)
        {
            SystemLogCls OSystemLogCls = new SystemLogCls();
            OSystemLogCls.LogAccessId = (string)dr["LogAccessId"];
            if (dr["LogAccessDate"] != DBNull.Value)
            {
                OSystemLogCls.LogAccessDate = (DateTime)dr["LogAccessDate"];
            }
            if (dr["Action"] != DBNull.Value)
            {
                OSystemLogCls.Action = (string)dr["Action"];
            }
            if (dr["ActionText"] != DBNull.Value)
            {
                OSystemLogCls.ActionText = (string)dr["ActionText"];
            }
            OSystemLogCls.UserId = (string)dr["UserId"];
            OSystemLogCls.LoginName = (string)dr["LoginName"];
            OSystemLogCls.FullName = (string)dr["FullName"];
            return OSystemLogCls;
        }

        public static SystemLogCls[] ParseFromDataTable(DataTable dtTable)
        {
            SystemLogCls[] SystemLogs = new SystemLogCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                SystemLogs[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return SystemLogs;
        }

    }
}


